//
//  KSUInfoItem.swift
//  ANOA
//
//  Created by 邱仙凯 on 2022/4/25.
//  Copyright © 2025 aowang. All rights reserved.
//  定制的一个item 类型

import UIKit
 import Kingfisher
class KSUInfoItem: KSFormHItem {
    // MARK: - 懒加载 lazy
     lazy var icon:UIButton = {
        let v = UIButton()
         v.layer.masksToBounds = true
         v.layer.cornerRadius = 5
        return v
    }()
    lazy var nameLab:UILabel = {
       let v = UILabel()
       return v
   }()
    var iconTouchClo:(()->())?
    convenience init(appearance: KSFormBaseAppear? = KSFormBaseAppear()) {
        self.init(title: "", appearance: appearance,type:.uinfo)
        
        self.addSubview(icon)
        icon.addTouchUpInSideAction { _ in
            if let clo = self.iconTouchClo {
                clo()
            }
        }
        icon.snp.makeConstraints { make in
             make.height.equalTo(58)
            make.width.equalTo(58)
             make.left.equalTo(self).offset(15)
            make.centerY.equalTo(self)
        }
        self.addSubview(nameLab)
        nameLab.snp.makeConstraints { make in
             make.left.equalTo(icon.snp.right).offset(15)
            make.centerY.equalTo(self)
        }
      }
 
    func setIcon(image:UIImage) {
         icon.setImage(image, for: .normal)
 
     }
    func setIconName(iconUrl:String,placeholder:UIImage? = nil,name:String) {
        if  let imageUrl = URL(string: iconUrl) {
            let resource = KF.ImageResource(downloadURL: imageUrl)
            icon.kf.setImage(with: resource, for: .normal, placeholder: placeholder)
         }
        nameLab.text = name
     }
}
